﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BMPTOPNG
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void _ctlBtnBrower_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        }

        private void _ctlBtnConvert_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.IO.FileInfo[] files = new System.IO.DirectoryInfo(dlg.SelectedPath).GetFiles("*.bmp");
                
                // 备份旧文件
                string bakDir = dlg.SelectedPath + ".bak";
                if (!System.IO.Directory.Exists(bakDir))
                {
                    System.IO.Directory.CreateDirectory(bakDir);
                    foreach (System.IO.FileInfo sFile in files)
                    {
                        System.IO.File.Copy(sFile.FullName, string.Format("{0}\\{1}.bmp", bakDir, sFile.Name));
                    }
                }
                foreach (System.IO.FileInfo sFile in files)
                {
                    ImageUtil.ConvertToPNG(sFile.FullName);
                    System.IO.File.Delete(sFile.FullName);
                }
                MessageBox.Show("转换完成!");
            }
        }

        private void _ctlBtnConvertFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ImageUtil.ConvertToPNG(dlg.FileName);
                MessageBox.Show("转换完成!");
            }
        }
    }
}
